"""
类成员属性举例: property
"""

class Person():
    """
    说明文档：
    这是一个描述人的类
    """
    def fget(self):
        return self._name
    def fset(self, name):
        self._name = name.upper()
    def fdel(self):
        self._name = None
    name = property(fget, fset, fdel, "设置属性案例")  #直接使用这个property函数设置属性

p = Person()
p.fset("zhangsan")
print(p.fget())

print(Person.__dict__)
print(Person.__doc__)
print(Person.__bases__)
print(Person.__name__)


#call举例
class A():
    def __init__(self):
        print("A is init")
    def __call__(self, *args, **kwargs):
        print("A is Call")
    def __str__(self):
        return "this is a string"
a = A()
a()
print(a)

class Person():
    def __setattr__(self, key, value):
        print("set attribute {0} to {1}".format(key, value))
        #直接赋值会导致死循环
        #self.key = value
        #正确做法是对其父类进行设置属性
        super(Person, self).__setattr__(key, value)

p = Person()
p.age = 18

class A():
    #实例方法：
    def eat(self):
        print("eating...")

    #类方法
    @classmethod
    def play(cls):
        print(cls)
        print("playing")

    #静态方法，不需要传入参数
    @staticmethod
    def say():
        print("saying")

a = A()
a.eat() #访问实例方法
a.play() #访问类方法
A.play()
a.say() #静态方法
A.say()